//
//  ListViewController.m
//  LazyEnglish
//
//  Created by lanou3g on 16/1/5.
//  Copyright © 2016年 李洋. All rights reserved.
//

#import "ListViewController.h"
#import "ListCollectionViewCell.h"


@interface ListViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@end

@implementation ListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //返回按钮
    self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(lsftItemAction:)];
    
    [self addLayOut];
    
    
    
    




}

-(void)addLayOut{
    //配置layout属性
    UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing =20;
    layout.minimumLineSpacing =50;
    layout.itemSize =CGSizeMake(150, 150);
    layout.sectionInset =UIEdgeInsetsMake(20, 20, 20, 20);
    //创建collectionView
    UICollectionView *collectionView =[[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:layout];
    collectionView.backgroundColor =[UIColor redColor];
    
    //添加到父视图
    [self.view addSubview:collectionView];
    
    
    //设置代理
    collectionView.delegate =self;
    collectionView.dataSource =self;
    
    //注册
    //[collectionView registerClass:[ListCollectionViewCell class] forCellWithReuseIdentifier:@"ListCollectionViewCell"];
    [collectionView registerNib:[UINib nibWithNibName:@"ListCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"ListCollectionViewCell"];

    
}



#pragma mark   collectionView代理
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 20;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ListCollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"ListCollectionViewCell" forIndexPath:indexPath];
    cell.backImage.image =[UIImage imageNamed:@"1.jpg"];
    cell.tltie.text =@"英语优选";
    cell.play_count.text =@"112233";
    
    
    return cell;
}

-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


#pragma mark  返回
-(void)lsftItemAction:(UINavigationItem *)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}


@end
